<template>
     <!-- 1、标签跳转 -->

    <!-- <div class="goodlist">
       <router-link :to="'/home/goodsinfo'+item.id" tag="div" class="gooditem" v-for="item in goodlist" :key="item.id">
           <img :src="item.img_url" alt="">
           <h1 class="title">{{item.title}}</h1>
           <div class="info">
               <p class="price">
                   <span class="now">{{item.sell_price}}</span>
                   <span class="old">{{item.market_price}}</span>
               </p>
               <p class="sell">
                    <span>热卖中</span>                   
                    <span>剩{{item.stock_quantity}}件</span>
               </p>
           </div>
       </router-link>
       <mt-button type="danger"  size="large"  @click="getmore">加载更多</mt-button>
    </div> -->

    <!--2、js代码跳转 -->
    <div class="goodlist">
       <div class="gooditem" v-for="item in goodlist" :key="item.id" @click="godetail(item.id)">
           <img :src="item.img_url" alt="">
           <h1 class="title">{{item.title}}</h1>
           <div class="info">
               <p class="price">
                   <span class="now">{{item.sell_price}}</span>
                   <span class="old">{{item.market_price}}</span>
               </p>
               <p class="sell">
                    <span>热卖中</span>                   
                    <span>剩{{item.stock_quantity}}件</span>
               </p>
           </div>
       </div>
       <mt-button type="danger"  size="large"  @click="getmore">加载更多</mt-button>
    </div>
</template>
<script>
export default {
    data(){
        return {
            pageindex:1,
            goodlist:[]
        }
    },
    created(){
        this.getgoodlist()
    },
    methods:{
        // 获取商品列表
        getgoodlist(){
            this.$http.get('http://www.liulongbin.top:3005/api/getgoods?pageindex='+this.pageindex)
            .then(result=>{
                console.log(result.body)
                if(result.body.status===0){
                    // this.goodlist=result.body.message
                    this.goodlist=this.goodlist.concat(result.body.message)
                }
            })
        },
        //加载更多
        getmore(){
          this.pageindex++
          this.getgoodlist()
        },
        //跳到商品详情页面(编程式的导航)
        godetail(id){
            // this.$route是路由参数挂载的地方
            // this.$router是路由导航对象，实现路由的前进、后退、跳转等操作
            // console.log(this)
            this.$router.push("/home/goodsinfo/"+id)
        }
    }
}
</script>
<style lang="scss" scoped>
.goodlist{
    display: flex;
    flex-wrap: wrap;
    padding: 7px;
    justify-content: space-between;
    .gooditem{
        width: 49%;
        border: 1px solid #ccc;
        box-shadow: 0 0 8px #ccc;
        margin: 3px 0;
        padding: 2px;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        height: 286px;
        img{
         width: 100%;
        }
        .title{
            font-size: 14px;
        }
        .info{
            background-color: #eee;
            p{
                margin: 0;
                padding: 5px;
            }
            .price{
               .now{
                   font-size: 16px;
                   color: red;
                   font-weight: 700;
               }
               .old{
                   font-size: 12px;
                   text-decoration: line-through;
                   margin-left: 10px;
               }
            }
            .sell{
                font-size: 13px;
                display: flex;
                justify-content: space-between;
            }
        }
    }
}
</style>